package StudyCode.summary.BufferAndChannel;

import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.SeekableByteChannel;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;

/**
 * 版权所有 科技与人文(www.tah1986.com)
 */
public class QueryPositionUsingSeekableByteChannel {
	public static void main(String[] args) throws IOException {
		Path path = Paths.get("E:/Copy/2.txt");
		final String newLine = System.getProperty("line.separator");
		try (SeekableByteChannel sbc = Files.newByteChannel(path, StandardOpenOption.WRITE)) {
			ByteBuffer buffer;
			long position = sbc.size();
			sbc.position(position);
			System.out.println("位置: " + sbc.position());

			buffer = ByteBuffer.wrap((newLine + "Using").getBytes());
			sbc.write(buffer);
			System.out.println("位置: " + sbc.position());
			buffer = ByteBuffer.wrap((newLine + "FileChannel").getBytes());
			sbc.write(buffer);
		}
	}
}
